// 1.通过字面量模式创建
/*
const ys = {
    name:'亚索',
    kh:"死亡如风，常伴吾身",
    hp:500,
    mp:0,
    nq:0,
    gjl:90,
    hj:50,
    skill:['斩钢闪','哈撒给'],
    attack:function(){
        console.log(`${this.kh}`)
        console.log('普通攻击')
    }
}
*/
/*构造函数模式，对位传参
function Hero(name,kh,hp,mp,nq,gjl,hj,skill){
    this.name = name
    this.kh = kh
    this.hp = hp
    this.mp = mp
    this.nq =nq 
    this.gjl =gjl 
    this.hj =hj 
    this.skill =skill 
    this.attack =function(){
        
        console.log('普通攻击')
    }
    this.say = function(){
        console.log(`${this.kh}`)
    }
}

const ys = new Hero("亚索","死亡如风，常伴吾身",500,0,0,90,50,['斩钢闪','哈撒给'])
*/
const ysOpt = {
    name: '亚索',
    kh: "死亡如风，常伴吾身",
    hp: 500,
    mp: 0,
    nq: 0,
    gjl: 90,
    hj: 50,
    skill: {
        q:{name:'斩钢闪',gjl:120} ,
        r: {name:'哈撒给',gjl:100} 
    }
}
const zxOpt = {
    name: '赵信',
    kh: "长枪依在，菊花拿来",
    hp: 501,
    mp: 200,
    nq: 0,
    gjl: 80,
    hj: 60,
    skill: {
        q: {name:'三重打击',gjl:200},
        w: {name:'三重打击',gjl:20}
    }
}
/**/
function Hero(heroOpt) {
    this.name = heroOpt.name
    this.kh = heroOpt.kh
    this.hp = heroOpt.hp
    this.mp = heroOpt.mp
    this.nq = heroOpt.nq
    this.gjl = heroOpt.gjl
    this.hj = heroOpt.hj
    this.skill = heroOpt.skill
    this.money = 1000
    //装备栏
    this.zbList = []
    Hero.prototype.attack = function(otherHero){
        const loseHp = this.gjl*(1 - otherHero.hj/250)
        otherHero.hp -= loseHp
        console.log(`${this.name}攻击${otherHero.name}了下，掉了${loseHp}`)
    }
    Hero.prototype.buyZb = function(zb){
        if(this.money < zb.buyPrice){
            console.log('你个穷逼！')
            return 
        } 
        this.money -= zb.buyPrice
        this.zbList.push(zb)
        this.hp += zb.hp
        this.hj += zb.hj
        this.gjl += zb.gjl
        console.log(`购买装备${zb.name}成功`)
    }
    Hero.prototype.sellZb = function(index){
        //拿到要卖的装备
        const zb = this.zbList[index]
        if(!zb){
            console.log('该操作无效')
            return
        }
        this.zbList.splice(index,1)
        this.money += zb.sellPrice
        this.hp -= zb.hp
        this.hj -= zb.hj
        this.gjl -= zb.gjl
        console.log(`s卖出装备${zb.name}成功`)
    }
   
}


const ys = new Hero(ysOpt)
const zx = new Hero(zxOpt)
/** 
function Hero(heroOpt) {
    this.name = heroOpt.name
    this.kh = heroOpt.kh
    this.hp = heroOpt.hp
    this.mp = heroOpt.mp
    this.nq = heroOpt.nq
    this.gjl = heroOpt.gjl
    this.hj = heroOpt.hj
    this.skill = heroOpt.skill,
    this.zbList = []

    Hero.prototype.attack = function (otherHero) {
        //this 代表攻击的英雄
        //otherHero 代表被攻击的英雄
        this.say()
        const loseHp = this.gjl * (1 - (otherHero.hj / 250))
        otherHero.hp -= loseHp
        console.log(`${this.name}普通攻击了${otherHero.name}`)
        console.log(`${otherHero.name}损失血量${loseHp}，剩余血量${otherHero.hp}`)

    }
    Hero.prototype.say = function () {
        console.log(`${this.kh}`)
    }
    //获得装备
    Hero.prototype.getZb = function(zb){
        if(this.zbList.length >= 3){
            console.log('物品栏以及满了')
            return
        }
        this.zbList.push(zb)
        this.hp += zb.hp
        this.gjl += zb.gjl
        this.mp += zb.mp
        this.hj += zb.hp
        console.log(`${this.name}获得了装备${zb.name}`)
    }
    //按照索引删除装备
    Hero.prototype.deleteZb = function(index){
        const deleteZb = this.zbList[index]
        this.zbList.splice(index,1)
        console.log(`${this.name}丢掉了装备${deleteZb.name}`)
    }
}

Hero.prototype.useSkill = function (key,otherHero) {
    const skillName = this.skill[key].name
    const loseHp = this.skill[key].gjl * (1 - (otherHero.hj / 250))
    otherHero.hp -= loseHp
    console.log(`${this.name}用技能${skillName}攻击了${otherHero.name}`)
    console.log(`${otherHero.name}损失血量${loseHp}，剩余血量${otherHero.hp}`)
}

const ys = new Hero(ysOpt)
const zx = new Hero(zxOpt)

// ys.attack(zx)
*/
const wjzrOpt = {
    name:'无尽之刃',
    gjl:80,
    hp:200,
    mp:0,
    hj:10,
    buyPrice:300,
    sellPrice:160,
}
const sxzlOpt = {
    name:"三相之力",
    gjl:80,
    hp:200,
    mp:100,
    hj:10,
    buyPrice:200,
    sellPrice:100,
}

function Weapon(opt){
    this.name = opt.name
    this.gjl = opt.gjl
    this.hp = opt.hp
    this.hj =opt.hj
    this.buyPrice = opt.buyPrice
    this.sellPrice = opt.sellPrice

    Weapon.prototype.type = "攻击类"
}

const wjzr = new Weapon(wjzrOpt)
const sxzl = new Weapon(sxzlOpt)
